Skip to content

Cargo run tool#3832

Draft
timon-schelling wants to merge 4 commits intomasterfrom
cargo-run-tool
Draft

Cargo run tool#3832
timon-schelling wants to merge 4 commits intomasterfrom
cargo-run-tool

Conversation

@timon-schelling
Copy link
Member

depends on #3808

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @timon-schelling, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the project's build and execution mechanisms by introducing a new Rust-based command-line tool. This tool consolidates various npm run and cargo run commands into a single, unified cargo run interface, improving consistency and ease of use for developers. The change also involves a cleanup of the Nix flake setup and removal of redundant root-level JavaScript package files, simplifying the overall project structure.

Highlights

  • Unified Build/Run Tool: Introduced a new tools/building Rust crate to centralize and simplify project build and run commands, replacing various npm run scripts with a single cargo run interface.
  • Nix Configuration Refactoring: Refactored the Nix flake configuration by moving core logic to .nix/default.nix and simplifying the root flake.nix, enhancing modularity and clarity.
  • Dependency Management Cleanup: Removed root-level package.json and package-lock.json files, streamlining the project's dependency management by centralizing frontend scripts within the frontend directory.
  • Documentation Update: Updated project setup documentation to reflect the new cargo run commands for web and desktop development, ensuring users have accurate instructions.
Changelog
  • .envrc
    • Removed the direnv configuration for Nix flakes.
  • .nix/default.nix
    • Added a new Nix file containing the main flake outputs definition, including packages, devShells, and formatter.
  • .nix/flake.nix
    • Removed, as its functionality was split and moved.
  • .nix/shell.nix
    • Removed, simplifying the Nix development environment setup.
  • Cargo.lock
    • Updated to include the new building package.
  • Cargo.toml
    • Added tools/building to workspace members and default members.
    • Removed node-graph/graphene-cli from default members.
  • flake.lock
    • Renamed from .nix/flake.lock.
    • Updated to remove the flake-compat input.
  • flake.nix
    • Added a simplified root flake file that imports the main configuration from .nix/default.nix.
  • package-lock.json
    • Removed the root-level npm lock file.
  • package.json
    • Removed the root-level npm package file, centralizing frontend scripts within the frontend directory.
  • tools/building/Cargo.toml
    • Added the manifest for the new building Rust crate.
  • tools/building/src/lib.rs
    • Added utility functions for executing shell commands and handling build profiles.
  • tools/building/src/main.rs
    • Added the main entry point for the building tool, providing subcommands for web and desktop operations (run/build) with profile selection.
  • website/content/volunteer/guide/project-setup/_index.md
    • Updated project run commands from npm start to cargo run.
    • Adjusted profiling and production commands to use the new cargo run syntax.
Ignored Files
  • Ignored by pattern: .github/workflows/** (3)
    • .github/workflows/build-linux-bundle.yml
    • .github/workflows/build-nix-package.yml
    • .github/workflows/provide-shaders.yml
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new building crate to replace the root package.json scripts for running and building the project, which is a great simplification. However, I've found a few issues in the implementation of this new tool. The command runner can panic on empty command strings, and the argument parsing logic doesn't correctly handle all the commands mentioned in the updated documentation, specifically cargo run build and cargo run -- production. I've provided suggestions to fix these issues, along with some minor improvements for code clarity and correctness.

impl From<&str> for Profile {
fn from(arg: &str) -> Self {
match arg {
"release" => Profile::Release,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The documentation was updated to use cargo run -- production, but this from implementation doesn't handle the "production" string. This will result in an error. You should also handle "production" as a Profile::Release.

Suggested change
"release" => Profile::Release,
"release" | "production" => Profile::Release,

Comment on lines +40 to +44
let comand = comand.split_whitespace().collect::<Vec<_>>();
let mut cmd = process::Command::new(comand[0]);
if comand.len() > 1 {
cmd.args(&comand[1..]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation will panic if an empty command string is passed to run_from, because comand.split_whitespace().collect::<Vec<_>>() will be an empty vector, and comand[0] will be an out-of-bounds access. This can be handled more robustly and efficiently by using an iterator directly, which also avoids an intermediate allocation.

	let mut parts = comand.split_whitespace();
	let Some(program) = parts.next() else { return };
	let mut cmd = process::Command::new(program);
	cmd.args(parts);

["build", rest @ ..] => build_desktop(rest.into()),
_ => run_desktop(rest.into()),
},
rest => run_web(rest.into()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The documentation was updated to use cargo run build, but this command is not handled here. It will fall into the rest case, which will try to parse "build" as a profile, fail, and show the usage message. You should add a case to handle the build command directly, which can default to building the web version.

		["build", rest @ ..] => build_web(rest.into()),
		rest => run_web(rest.into()),


impl From<&[&str]> for Profile {
fn from(arg: &[&str]) -> Self {
arg.first().map(|s| s.to_string()).as_deref().unwrap_or_default().into()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This from implementation can be simplified for better readability and to avoid an unnecessary string allocation.

Suggested change
arg.first().map(|s| s.to_string()).as_deref().unwrap_or_default().into()
arg.first().copied().unwrap_or("").into()

run_from(comand, Some("frontend"));
}

pub fn run_from(comand: &str, dir: Option<&str>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a typo in the parameter name comand. It should be command. This typo appears in several places in this file (run, run_in_frontend_dir, run_from and its body). Please correct it throughout the file for consistency and clarity.

Suggested change
pub fn run_from(comand: &str, dir: Option<&str>) {
pub fn run_from(command: &str, dir: Option<&str>) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant